package com.atguigu.exercise.exer1;

/*
public class Test{
    public Test(){
        Inner s1 = new Inner();
        s1.a = 10;
        Inner s2 = new Inner();
        s2.a = 20;
        Test.Inner s3 = new Test.Inner();
        System.out.println(s3.a);
    }
    //上面的代码没有执行，单纯是干扰代码。
    static class Inner{
        public int a = 5;//它的默认值被指定为5
    }
    public static void main(String[] args) {
        Test.Inner r = new Test.Inner();
        System.out.println(r.a);//5
    }
}*/

public class Test{
    public Test(){
        Inner s1 = new Inner();
        s1.a = 10;
        Inner s2 = new Inner();
        s2.a = 20;
        Inner s3 = new Inner();
        System.out.println(s3.a);//5
        //s1,s2,s3对象的a都是独立的
    }

    class Inner{
        public int a = 5;//非静态的实例变量。所有Inner对象各有一份，独立的。
    }
    public static void main(String[] args) {
        Inner r = new Test().new Inner();
        System.out.println(r.a);//5
        //r对象与上面的s1,s2,s3也是独立的的
    }
}
